package com.example.databanding;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import com.example.databanding.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    MyViewModel myModel;
    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);

        //创建了binding对象 可以理解成当前activity的binding？
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);
        myModel = new ViewModelProvider(this).get(MyViewModel.class);

        binding.textView.setText("binding!!!!!!");
        binding.setData(myModel);
        binding.setLifecycleOwner(this); //这个是让绑定起作用， 必须要有
    }

}
